import javax.swing.tree.TreeNode;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        Stack<Integer> stack1 = new Stack<Integer>();
        System.out.println("Hello world!");
    }
    public int size(TreeNode root){
        /*int size = 0;
        if(root == null) return 0;
        int sizeLeft = size(root.left);
        size += sizeLeft;
        int sizeRight = size(root.right);
        size += sizeRight;
        return size + 1;*/
        int size = root == null? 0 : size(root.left) +size(root.right);
        return size + 1;
    }
    int size = 0;
    public void getLeafNodeCount(TreeNode root) {
        if(root == null) return;
        if(root.left == null && root.right ==null){
            size++;
        }
        getLeafNodeCount(root.left);
        getLeafNodeCount(root.right);
        System.out.println(size);
    }


    public int getLeafNodeCount2(TreeNode root) {
        int size = 0;
        if(root == null) return 0;
        if(root.left == null && root.right ==null){
            size++;
        }
        size = getLeafNodeCount2(root.left)+getLeafNodeCount2(root.right);
        return size;
    }
    public int getKLeveNodeCount(TreeNode root, int k){
        int count = 0;
        if(root == null || k <= 0){
            return 0;
        }
        if(k == 1) {
            return 1;
        }
        count = getKLeveNodeCount(root.left,k-1) + getKLeveNodeCount(root.right,k-1);
        return count;
    }

    public TreeNode findVal(TreeNode root,char val) throws NullPointerException{
        if(root == null){
            return null;
        }
        if(root.val == val){
            return root;
        }
        TreeNode ret = findVal(root.left,val);
        if(ret != null){
            return ret;
        }
        ret = findVal(root.right,val);
        return ret;
    }
}